/**
 * 
 */
package tani.bnn.com.mbilling.utility;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.StringTokenizer;

/**
 * @author netesh.thukral
 *
 */
public class DateUtils {
	  public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
	  public static final String DATE_MONTH_FORMAT = "dd-MM-yyyy";
	  public static final String DATE_FILE_FORMAT = "dd_MM_yyyy_HH_mm_ss";

	  public static String now() {
	    Calendar cal = Calendar.getInstance();
	    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
	    return sdf.format(cal.getTime());
	  }
	  public static String now(String dateFormat) {
		  Calendar cal = Calendar.getInstance();
		  SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);

/*		  System.out.println(DateUtils.now("dd MMMMM yyyy"));
	      System.out.println(DateUtils.now("yyyyMMdd"));
	      System.out.println(DateUtils.now("dd.MM.yy"));
	      System.out.println(DateUtils.now("MM/dd/yy"));
	      System.out.println(DateUtils.now("yyyy.MM.dd G 'at' hh:mm:ss z"));
	      System.out.println(DateUtils.now("EEE, MMM d, ''yy"));
	      System.out.println(DateUtils.now("h:mm a"));
	      System.out.println(DateUtils.now("H:mm:ss:SSS"));
	      System.out.println(DateUtils.now("K:mm a,z"));
	      System.out.println(DateUtils.now("yyyy.MMMMM.dd GGG hh:mm aaa"));	*/	  

	      return sdf.format(cal.getTime());
	  }
	  public static Date getMonthStart(String monthYear) throws ParseException {
		  Date date = null;
		  String dayMonthYear = "01-" + monthYear;
		  SimpleDateFormat sdf = new SimpleDateFormat(DATE_MONTH_FORMAT);
		  date = sdf.parse(dayMonthYear);
		  return date;
	  }
	  public static Date getMonthEnd(String monthYear) throws ParseException {
		  Date date = null;
		  StringTokenizer stkn = new StringTokenizer(monthYear, "-");
		  String dayMonthYear = "01-" + (Integer.parseInt(stkn.nextToken()) + 1);
		  dayMonthYear += "-" + stkn.nextToken();
		  SimpleDateFormat sdf = new SimpleDateFormat(DATE_MONTH_FORMAT);
		  date = sdf.parse(dayMonthYear);
		  return date;
	  }
	  public static Date getDateValue(String dateValue) throws ParseException {
		  Date dt = null;
		  SimpleDateFormat sdf = new SimpleDateFormat(DATE_MONTH_FORMAT);
		  dt = sdf.parse(dateValue);
		  return dt;
	  }
	  public static Date getDateValue(String dateValue, String dateFormat) throws ParseException {
		  Date dt = null;
		  SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
		  dt = sdf.parse(dateValue);
		  return dt;
	  }
	public static String formattedDate(java.sql.Date sopDate, String dateFormatNow) {
		SimpleDateFormat sdf = new SimpleDateFormat(dateFormatNow);
		return sdf.format(sopDate);
	}
}
